<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Setoran_kasir_model extends CI_Model{
	function __construct() {
		parent::__construct();
	}
	
	function get_all($date=''){
		
		if($date==''){
			$date=date('Ymd');
		}else{
			$date = $this->date_func->change_format_date($date,'d-m-Y','Ymd');
		}
		
		$this->db->where('tanggal', $date);
		$this->db->where('is_closing', 0);
		return $this->db->get('TblSetoran')->result_array();
	}
	
	function get_one($no_spj){
		$query = $this->db->get_where('TblSetoran',array('NoSPJ'=>$no_spj));
		if($query->num_rows()>0){
			return $query->row_array();
		}else{
			return FALSE;
		}
	}
        
        function get_kasir($tgl_awal,$tgl_akhir)
        {
            if($tgl_awal==''){
			$tgl_awal=date('Ymd');
		}else{
			$tgl_awal=$this->date_func->change_format_date($tgl_awal,'d-m-Y','Ymd');
		}
		if($tgl_akhir==''){
			$tgl_akhir=date('Ymd');
		}else{
			$tgl_akhir=$this->date_func->change_format_date($tgl_akhir,'d-m-Y','Ymd');
		}
                $this->db->where('tanggal BETWEEN "'.$tgl_awal.'" AND "'.$tgl_akhir.'"');
                $this->db->join('TbUser', 'TblSetoran.idkasirSetoran = TbUser.user_id', 'inner');
                $this->db->distinct();
                $this->db->select('idkasirSetoran,nama');
                return $this->db->get('TblSetoran')->result_array();
        }
        
        
        function get_cabang_by_user($idkasirSetoran)
        {
                $this->db->join('TbMDCabang', 'TbMDCabang.Nama = TblSetoran.cabang_keberangkatan', 'inner');
                $query = $this->db->get('TblSetoran');
                if($query->num_rows()>0){
			return $query->row_array();
		}else{
			return FALSE;
		}
        }


        function get_penerimaan_kasir($idkasirSetoran)
        {
            $this->db->select("SUM(total_penumpang) AS total_penumpang,SUM(tiket_void) AS tiket_void,SUM(total_omset) AS total_omset,
                SUM(total_discount) AS total_discount,SUM(fee_agen) AS fee_agen,SUM(total_void) AS total_void, SUM(jumlah) AS jumlah,
                SUM(total_setoran) AS total_setoran");
            $this->db->join('TblBiaya', 'TblBiaya.NoSPJ = TblSetoran.NoSPJ', 'inner');
            $this->db->where('idkasirSetoran',$idkasirSetoran);
            $this->db->where('is_tujuan',1);
            return $this->db->get('TblSetoran')->result_array();
        }
}

/** End of file */